package org.inspiration.dudu.web.controller.content;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.inspiration.dudu.common.pojo.Result;
import org.inspiration.dudu.content.model.dto.QuestionDTO;
import org.inspiration.dudu.content.model.vo.QuestionSimpleVO;
import org.inspiration.dudu.content.model.vo.QuestionVO;
import org.inspiration.dudu.web.annotation.Loggable;
import org.inspiration.dudu.web.service.content.QuestionFacadeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/questions")
@Tag(name = "问题接口", description = "提供与问题相关的操作接口")
@RequiredArgsConstructor
@Loggable

public class QuestionController {

    private final QuestionFacadeService questionFacadeService;

    @PostMapping
    @Operation(summary = "上传问题", description = "接收用户提交的问题并返回其唯一标识符")
    public Result<String> uploadQuestion(@RequestBody QuestionDTO questionDTO) {
        String uuid = questionFacadeService.uploadQuestion(questionDTO);
        // 返回生成的唯一标识符
        return Result.success(uuid);
    }

    @Operation(summary = "根据id查询问题", description = "根据问题ID获取具体的问题信息")
    @GetMapping("/{id}")
    public Result<QuestionVO> getQuestionById(@PathVariable("id") String id) {
        QuestionVO questionVO = questionFacadeService.getQuestionById(id);
        return Result.success(questionVO);
    }

    @Operation(summary = "查询最近问题", description = "分页倒序")
    @GetMapping("/desc")
    public Result<List<QuestionVO>> getQuestionsOrderByDESC(@RequestParam("pageNum") Integer pageNum,
                                                            @RequestParam("pageSize") Integer pageSize) {
        List<QuestionVO> list = questionFacadeService.getQuestionOrderByDESC(pageNum, pageSize);
        return Result.success(list);
    }

    @Operation(summary = "获取用户最近提问")
    @GetMapping("/user")
    public Result<List<QuestionVO>> getQuestionsByUserIdOrderByDESC(
            @RequestParam("userId") Long userId,
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize) {
        List<QuestionVO> list = questionFacadeService.getQuestionsByUserIdOrderByDESC(userId, pageNum, pageSize);
        return Result.success(list);
    }

}
